<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 1
    function foo() {
      console.log('foo:', this)
    }
    foo()

    // 2
    var obj = {
      name: "why",
      bar: function () {
        console.log('bar:', this)
      }
    }
    var baz = obj.bar
    baz()

    // 3. 高阶函数
    function test(fn){
      fn()
    }
    test(obj.bar)


  </script>

  <script>
    // 严格模式下,独立调用的函数中的this指向的是undefined

    "use strict"
    function foo() {
      console.log('foo:', this)
    }
    foo()

    // 2
    var obj = {
      name: "why",
      bar: function () {
        console.log('bar:', this)
      }
    }
    var baz = obj.bar
    baz()

  </script>
</body>

</html>